#include <arv.h>
#include <png.h>
#include <string>
#include <mutex>
#include <condition_variable>
#include <thread>
#include <chrono>

#include "../image/imageIO.h"


namespace DataCollection{
    namespace Camera{

        class CameraController{
            public:
                /* 连接相机  USB(default)  IPV4 */
                CameraController(std::string address = "");

                /* 关闭相机 */
                ~CameraController();

                /* 测试参数 */
                void test_param();

                /* 视频流 */
                void collection_voide();

                /* 单帧采集 */
                void collection_single_frame();

            private:
                /* 保存图像的线程 */
                void save_image(
                    unsigned char *data_image,
                    std::time_t timestamp_collection,
                    int width, 
                    int height, 
                    int bit_depth=8, 
                    int color_type=PNG_COLOR_TYPE_RGB
                    );

                // 图像保存
                Image::ImageSaver image_saver;

                std::string address = "";
                ArvCamera *camera;
                int width = 5472;
                int height = 3648;
                unsigned int num_buffer = 5;

                // 控制多线程的变量
                std::mutex mtx;
                std::condition_variable cv;
                bool error_occurred = false;
                std::string error_message;
                time_t  time_last_save = 0;
        };

    } // Camera
} // DataCollection
